/*
 * @Author: zhangxf
 * @Date: 2023-08-30 10:49:45
 * @Last Modified by: zhangxf
 * @Last Modified time: 2023-09-14 20:30:56
 */
export default {
  state: {
    isShow: false,
    defaultInfo: {
      type: 0, //0 alert 1 confirm
      title: "提示：", // 头部提示
      desc: "", //详细内容
      icon: "msg", //图标名
      autoConfirmClose: true, //点击确认是否自动关闭
      autoCancelClose: true, //点击取消是否自动关闭
    },
    dialogInfo: {},
    _promise: Promise,
    _promiseResolve: null,
    _promiseReject: null,
  },
  mutations: {
    /**
     * @description 探窗信息赋值
     * @author zhangxf
     * @date 30/08/2023 05:08:44
     * @param {*} state
     * @param {*} dialogInfo
     */
    set_dialog_info(state, dialogInfo) {
      state.dialogInfo = { ...dialogInfo };
    },
    /**
     * @description 弹窗状态赋值
     * @author zhangxf
     * @date 30/08/2023 05:08:25
     * @param {*} state
     * @param {*} status
     */
    set_dialog_status(state, status) {
      state.isShow = status;
    },
    set_confirm(state, resolve) {
      state._promiseResolve = resolve;
    },
    set_cancel(state, reject) {
      state._promiseReject = reject;
    },
  },
  actions: {
    /**
     * @description 显示弹窗
     * @author zhangxf
     * @date 30/08/2023 05:08:40
     * @param {*} { commit }
     * @param {*} opt
     */
    show({ commit, state }, opt) {
      state._promise = new Promise(function (resolve, reject) {
        commit("set_dialog_status", true);
        commit("set_dialog_info", { ...state.defaultInfo, ...opt });
        commit("set_confirm", resolve);
        commit("set_cancel", reject);
      });
      return state._promise;
    },
  },
};
